/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.toools.gwt.wmc.client.application.gui;

import org.toools.gwt.widget.client.bc.BasicControl;
import org.toools.gwt.widget.client.bc.BasicListener;
import org.toools.gwt.widget.client.bc.DefaultCreateCallback;
import org.toools.gwt.widget.client.bc.DefaultDeleteCallback;
import org.toools.gwt.widget.client.bc.DefaultUpdateCallback;
import org.toools.gwt.wmc.client.application.ApplicationService;
import org.toools.gwt.wmc.jpa.Application;

/**
 *
 * @author manuel
 */
public class ApplicationListener extends BasicListener{

    public ApplicationListener(BasicControl bc) {
        super(bc);
    }

    @Override
    public void onCreate(Object o) {
        Application a = (Application) o;
        DefaultCreateCallback dcc = new DefaultCreateCallback(o, this) {
            public String getOnFailureMessage(Throwable t) {
                return "creation failed: " + t.getMessage();
            }
        };
        ApplicationService.Util.getInstance().create(a, dcc);
    }

    @Override
    public void onUpdate(Object o) {
        Application a = (Application) o;
        DefaultUpdateCallback duc = new DefaultUpdateCallback(o, this) {
            public String getOnFailureMessage(Throwable t) {
                return "update failed: " + t.getMessage();
            }
        };
        ApplicationService.Util.getInstance().update(a,  duc);
    }

    @Override
    public void onDelete(Object o) {
        Application a = (Application) o;
        DefaultDeleteCallback ddc = new DefaultDeleteCallback(o, this);
        ApplicationService.Util.getInstance().delete(a, ddc);
    }

}
